using Header;
public delegate void RequestHandler(HttpContext context);
public class HttpServer {
    private RequestHandler on_request;
    public Gee.Map<string, Type> headerHandlers;
    public SocketService socketService {get; private set;}
    public void set_request_handler(RequestHandler handler) {
        this.on_request = handler;
    }
    public HttpServer(SocketService service) {
        this.socketService = service;
        service.incoming.connect((clientSocket, sourceObject) => {
            HttpContext.from_client_connection.begin(this, clientSocket, (response, asyncResult) => {
                try {
                    var context = HttpContext.from_client_connection.end(asyncResult);
                    on_request(context);
                } catch (IOError error) {
                    clientSocket.close_async();
                } catch (HttpProtocolError error) {
                    clientSocket.close_async();
                }
            });
            return true;
        });
        register_basic_header_handlers();
    }
    private void register_basic_header_handlers() {
        this.headerHandlers = new Gee.HashMap<string, Type>();
        headerHandlers[Header.ContentLength.KEY] = typeof(ContentLength);
        headerHandlers[Header.ContentType.KEY] = typeof(Header.ContentType);
    }
}